package com.hellohoper.test.mybatis.mapper;

import com.hellohoper.test.mybatis.mapper.model.CityDistance;
import com.hellohoper.test.mybatis.mapper.provider.CityDistanceSqlProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface CityDistanceMapper {

    @Delete({
            "delete from city_distance",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into city_distance (id, dep_city_code, ",
            "arr_city_code, distance, ",
            "is_del, create_time, ",
            "update_time, dep_city_name, ",
            "arr_city_name)",
            "values (#{id,jdbcType=BIGINT}, #{depCityCode,jdbcType=VARCHAR}, ",
            "#{arrCityCode,jdbcType=VARCHAR}, #{distance,jdbcType=VARCHAR}, ",
            "#{isDel,jdbcType=BIT}, #{createTime,jdbcType=TIMESTAMP}, ",
            "#{updateTime,jdbcType=TIMESTAMP}, #{depCityName,jdbcType=VARCHAR}, ",
            "#{arrCityName,jdbcType=VARCHAR})"
    })
    int insert(CityDistance record);

    @InsertProvider(type = CityDistanceSqlProvider.class, method = "insertSelective")
    int insertSelective(CityDistance record);

    @Select({
            "select",
            "id, dep_city_code, arr_city_code, distance, is_del, create_time, update_time, ",
            "dep_city_name, arr_city_name",
            "from city_distance",
            "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "dep_city_code", property = "depCityCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "arr_city_code", property = "arrCityCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "distance", property = "distance", jdbcType = JdbcType.VARCHAR),
            @Result(column = "is_del", property = "isDel", jdbcType = JdbcType.BIT),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "dep_city_name", property = "depCityName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "arr_city_name", property = "arrCityName", jdbcType = JdbcType.VARCHAR)
    })
    CityDistance selectByPrimaryKey(Long id);

    @SelectProvider(type = CityDistanceSqlProvider.class, method = "selectPageList")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "dep_city_code", property = "depCityCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "arr_city_code", property = "arrCityCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "distance", property = "distance", jdbcType = JdbcType.VARCHAR),
            @Result(column = "is_del", property = "isDel", jdbcType = JdbcType.BIT),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "dep_city_name", property = "depCityName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "arr_city_name", property = "arrCityName", jdbcType = JdbcType.VARCHAR)
    })
    List<CityDistance> selectPageList(CityDistance record);

    @UpdateProvider(type = CityDistanceSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(CityDistance record);

    @Update({
            "update city_distance",
            "set dep_city_code = #{depCityCode,jdbcType=VARCHAR},",
            "arr_city_code = #{arrCityCode,jdbcType=VARCHAR},",
            "distance = #{distance,jdbcType=VARCHAR},",
            "is_del = #{isDel,jdbcType=BIT},",
            "create_time = #{createTime,jdbcType=TIMESTAMP},",
            "update_time = #{updateTime,jdbcType=TIMESTAMP},",
            "dep_city_name = #{depCityName,jdbcType=VARCHAR},",
            "arr_city_name = #{arrCityName,jdbcType=VARCHAR}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(CityDistance record);
}